#ifndef BMPBUTTON_H
#define BMPBUTTON_H

#include <QPushButton>
#include "textview.h"

typedef struct tagBmpButtonInfo
{
	QRect crect; //geometry
	QString text;
	QString bmpPath;
	QString bmpPathHovered;
	QString bmpPathPressed;
	QString bmpPathX;	
	QRect rectBmp;	
	QRect rectTxt;
	int fontSize;
    int fontWeight;
	QColor txtColor;
    QColor txtColorPressed;
	int flag;
	bool bCheckTxtLen;
    int icon; //iconfont

public:
	tagBmpButtonInfo () {
		revert();
	}

	void revert() {
        icon = 0;
        fontSize = 20;
        fontWeight = 700;
		rectBmp.setRect(0, 0, 0, 0);
		rectTxt.setRect(0, 0, 0, 0);
		txtColor = QColor(0, 0, 0);	
        txtColorPressed = QColor(0, 204, 255);
		flag = Qt::AlignCenter;
		text.clear();
		bmpPath.clear();
		bmpPathHovered.clear();
		bmpPathPressed.clear();
		bmpPathX.clear();	
		bCheckTxtLen = false; //为true时检查text是否能显示完整
	}

} BMPBUTTON_INFO;

class BmpButton : public QPushButton
{
	Q_OBJECT

public:
	enum BMPBUTTON_TYPE {
		BUTTON4_TYPE = 0,  //支持4态（正常、按下、选中、禁用）按钮
		CHECKBOX_TYPE      //checkbox形式（选中、非选中）
        , BTN_ON_DOWN

	};
	BmpButton(QWidget * parent = 0);
	virtual ~BmpButton();

	void setUI(BMPBUTTON_INFO& ui);
	BMPBUTTON_INFO& getUI() { return mUI; }
	void setbmpPath(const QString& bmpPath, const QString& bmpPathPressed);
	void setIcon(const QString& iconPath, const QRect& iconRt);
	void setText(const QString& text, bool bUpdate=false);
	void setHint(QString& hint) {
		mHint = hint;
	}
	void setCheckTxtLen(bool bCheck)  {
		mUI.bCheckTxtLen = bCheck;
		mTxtToDraw.clear();
	}
	void setCheckBoxType();
    void setOnDownBtn();
	bool GetHovered() {return mHovered;}
public slots:
	void setHovered(bool hovered);
	void setPressed(bool pressed);
	void click();

protected:
	void paintEvent(QPaintEvent * pe);

	void mousePressEvent(QMouseEvent * e);
	void mouseReleaseEvent(QMouseEvent * e);	

signals:
	void sendKey(QString key);
	void onMouseDown();

private:

	void resetPixMap();

	BMPBUTTON_INFO mUI;
	bool mHovered; // 可作为check box 
	bool mPressed;

	QPixmap mbmp;
	QPixmap mbmpPressed;
	QPixmap mbmpHovered;
	QPixmap mbmpX;
	QPixmap mbmpIcon;

	QString mIcon;
	QRect   mIconRt;
	QString mHint;
	QString mTxtToDraw;
	BMPBUTTON_TYPE mBtnType;
};

#endif // BMPBUTTON_H

